﻿#pragma once

#include <iostream>
#include <fstream>

#include <string>
#include <sstream>
#include <vector>

int loadFilesDemo01(std::string input_path) {
    try
    {
        std::string buf;
        clock_t start = clock();
        std::ifstream fin(input_path);

        while (fin >> buf);

        fin.close();
        clock_t end = clock();
        std::cout << "time : " << ((double)end - start) / CLOCKS_PER_SEC << "s\n";
        return 0;
    }
    catch (const std::exception& err)
    {
        std::cout << err.what() << std::endl;
        return -1;
    }
    
}

// 目前来看这种方法读取大文件最快
int loadFilesDemo02(std::string input_path) {
    try
    {
        clock_t start = clock();
        std::ifstream fin(input_path, std::ios::binary);

        std::vector<char> buf(fin.seekg(0, std::ios::end).tellg());
        fin.seekg(0, std::ios::beg).read(&buf[0], static_cast<std::streamsize>(buf.size()));

        fin.close();
        clock_t end = clock();
        std::cout << "time : " << ((double)end - start) / CLOCKS_PER_SEC << "s\n";
        return 0;
    }
    catch (const std::exception& err)
    {
        std::cout << err.what() << std::endl;
        return -1;
    }
    
}

int loadFilesDemo03(std::string input_path) {
    try
    {
        clock_t start = clock();
        std::ifstream fin(input_path);

        std::stringstream buf;
        buf << fin.rdbuf();

        fin.close();
        clock_t end = clock();
        std::cout << "time : " << ((double)end - start) / CLOCKS_PER_SEC << "s\n";
        return 0;
    }
    catch (const std::exception& err)
    {
        std::cout << err.what() << std::endl;
        return -1;
    }
	
}
